package cn.itsy.dao;


import cn.itsy.pojo.*;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository
public class Pagedaoimpl implements Pagedao {
    @Resource
    private Empactdao ed;
    @Resource
    private Pactextdao ptd;
    @Resource
    private Pactypedao pd;
    @Resource
    private EmpsDao esd;
    @Resource
    private LituixiuDao lz;

    @Override
    public Page empactfy(String sql, String currentPage, Page page) {
        List<EmpandEmpact> count = ed.list(sql);
        page.setTotalCount(count.size());
        page.setPageSize(5);
        Integer totalPage = (int) Math.ceil((1.0 * page.getTotalCount() / page.getPageSize()));
        page.setTotalPage(totalPage);
        if (currentPage != null && !currentPage.equals("")) {
            page.setCurrentPage(Integer.valueOf(currentPage));//设置页数
        } else {
            page.setCurrentPage(1);
        }
        Integer start = (page.getCurrentPage() - 1) * page.getPageSize();// 计算开始行
        sql += " limit " + start + " , " + page.getPageSize();
        List<EmpandEmpact> el = ed.list(sql);
        page.setPl(el);
        return page;
    }

    @Override
    public Page pactextfy(String sql, String currentPage, Page page) {
        List<Pactext_type> count = ptd.list(sql);
        page.setTotalCount(count.size());
        page.setPageSize(5);
        Integer totalPage = (int) Math.ceil((1.0 * page.getTotalCount() / page.getPageSize()));
        page.setTotalPage(totalPage);
        if (currentPage != null && !currentPage.equals("")) {
            page.setCurrentPage(Integer.valueOf(currentPage));//设置页数
        } else {
            page.setCurrentPage(1);
        }
        Integer start = (page.getCurrentPage() - 1) * page.getPageSize();// 计算开始行
        sql += " limit " + start + " , " + page.getPageSize();
        List<Pactext_type> list = ptd.list(sql);
        page.setPl(list);
        return page;
    }

    @Override
    public Page pactypefy(String sql, String currentPage, Page page) {
        List<Pactype> count = pd.list(sql);
        page.setTotalCount(count.size());
        page.setPageSize(5);
        Integer totalPage = (int) Math.ceil((1.0 * page.getTotalCount() / page.getPageSize()));
        page.setTotalPage(totalPage);
        if (currentPage != null && !currentPage.equals("")) {
            page.setCurrentPage(Integer.valueOf(currentPage));//设置页数
        } else {
            page.setCurrentPage(1);
        }
        Integer start = (page.getCurrentPage() - 1) * page.getPageSize();// 计算开始行
        sql += " limit " + start + " , " + page.getPageSize();
        List<Pactype> list = pd.list(sql);
        page.setPl(list);
        return page;
    }

    @Override
    public Page empactjlfy(String sql, String currentPage, Page page) {
        List<EmpandEmpact> count = ed.emplist2(sql);
        page.setTotalCount(count.size());
        page.setPageSize(5);
        Integer totalPage = (int) Math.ceil((1.0 * page.getTotalCount() / page.getPageSize()));
        page.setTotalPage(totalPage);
        if (currentPage != null && !currentPage.equals("")) {
            page.setCurrentPage(Integer.valueOf(currentPage));//设置页数
        } else {
            page.setCurrentPage(1);
        }
        Integer start = (page.getCurrentPage() - 1) * page.getPageSize();// 计算开始行
        sql += " limit " + start + " , " + page.getPageSize();
        List<EmpandEmpact> list = ed.emplist2(sql);
        page.setPl(list);
        return page;
    }

    @Override
    public Page empshowfy(String sql, String currentPage, Page page) {
        List<Emp> count = esd.queryAll(sql);
        System.out.println(count.size());
        page.setTotalCount(count.size());
        page.setPageSize(15);
        Integer totalPage = (int) Math.ceil((1.0 * page.getTotalCount() / page.getPageSize()));
        page.setTotalPage(totalPage);
        if (currentPage != null && !currentPage.equals("")) {
            page.setCurrentPage(Integer.valueOf(currentPage));//设置页数
        } else {
            page.setCurrentPage(1);
        }
        Integer start = (page.getCurrentPage() - 1) * page.getPageSize();// 计算开始行
        sql += " limit " + start + " , " + page.getPageSize();
        List<Emp> list = esd.queryAll(sql);
        page.setPl(list);
        return page;
    }

    @Override
    public Page empTshowfy(String sql, String currentPage, Page page) {
        List<Emp> count = esd.queryAll(sql);
        System.out.println(count.size());
        page.setTotalCount(count.size());
        page.setPageSize(10);
        Integer totalPage = (int) Math.ceil((1.0 * page.getTotalCount() / page.getPageSize()));
        page.setTotalPage(totalPage);
        if (currentPage != null && !currentPage.equals("")) {
            page.setCurrentPage(Integer.valueOf(currentPage));//设置页数
        } else {
            page.setCurrentPage(1);
        }
        Integer start = (page.getCurrentPage() - 1) * page.getPageSize();// 计算开始行
        sql += " limit " + start + " , " + page.getPageSize();
        List<Emp> list = esd.queryAll(sql);
        page.setPl(list);
        return page;
    }

    @Override
    public Page empTshowfy2(String sql, String currentPage, Page page) {
        List<Emp> count = esd.queryAll(sql);
        System.out.println(count.size());
        page.setTotalCount(count.size());
        page.setPageSize(10);
        Integer totalPage = (int) Math.ceil((1.0 * page.getTotalCount() / page.getPageSize()));
        page.setTotalPage(totalPage);
        if (currentPage != null && !currentPage.equals("")) {
            page.setCurrentPage(Integer.valueOf(currentPage));//设置页数
        } else {
            page.setCurrentPage(1);
        }
        Integer start = (page.getCurrentPage() - 1) * page.getPageSize();// 计算开始行
        sql += " limit " + start + " , " + page.getPageSize();
        List<Emp> list = esd.queryAll(sql);
        page.setPl(list);
        return page;
    }

    @Override
    public Page empfy(String sql, String currentPage, Page page) {
        List<Emp> count = lz.emplist(sql);
        System.out.println(count.size());
        page.setTotalCount(count.size());
        page.setPageSize(10);
        Integer totalPage = (int) Math.ceil((1.0 * page.getTotalCount() / page.getPageSize()));
        page.setTotalPage(totalPage);
        if (currentPage != null && !currentPage.equals("")) {
            page.setCurrentPage(Integer.valueOf(currentPage));//设置页数
        } else {
            page.setCurrentPage(1);
        }
        Integer start = (page.getCurrentPage() - 1) * page.getPageSize();// 计算开始行
        sql += " limit " + start + " , " + page.getPageSize();
        List<Emp> list = lz.emplist(sql);
        page.setPl(list);
        return page;
    }

    @Override
    public Page empfy2(String sql, String currentPage, Page page) {
        List<Emp> count = lz.emplist(sql);
        System.out.println(count.size());
        page.setTotalCount(count.size());
        page.setPageSize(10);
        Integer totalPage = (int) Math.ceil((1.0 * page.getTotalCount() / page.getPageSize()));
        page.setTotalPage(totalPage);
        if (currentPage != null && !currentPage.equals("")) {
            page.setCurrentPage(Integer.valueOf(currentPage));//设置页数
        } else {
            page.setCurrentPage(1);
        }
        Integer start = (page.getCurrentPage() - 1) * page.getPageSize();// 计算开始行
        sql += " limit " + start + " , " + page.getPageSize();
        List<Emp> list = lz.emplist(sql);
        page.setPl(list);
        return page;
    }
}
